// 云函数入口文件
const cloud = require('wx-server-sdk')

cloud.init({
  traceUser: true,
  env:'aaa111-9gh9fp5ieac4de5d'
})

const db = cloud.database()

// 云函数入口函数
exports.main = async (event, context) => {
  const wxContent = cloud.getWXContext()
  try {
    return await db.collection('comment').add({
      data: {
        intro: event.maintext,
        _openid: wxContent.OPENID,
        timestamp: event.timestamp,
        artId: event.artId
      }
    })
  } catch(e) {
    console.error(e)
  }
}